<?php
/**
 * 装饰者模式
 * Created by PhpStorm.
 * User: tangzhou
 * Date: 16-9-1
 * Time: 下午10:03
 */

/**
 * 组件对象接口
 * Interface IComponent
 */
interface IComponent
{
    function Display();
}

/**
 * 带装饰对象
 * Class Person
 */
class Person implements IComponent
{
    private $name;

    function __construct($name)
    {
        $this->name = $name;
    }

    function Display()
    {
        echo "装扮的：{$this->name}<br/>";
    }
}


/**
 * 所有装饰器的父类
 * Class Clothes
 */
class Clothes implements IComponent
{
    protected $component;

    function Decorate($component)
    {
        $this->component = $component;
    }

    function Display()
    {
        if (!empty($this->component)) {
            $this->component->Display();
        }
    }
}

/**
 * 具体装饰器
 * Class pixie
 */
class pixie extends Clothes
{
    function Display()
    {
        echo "皮鞋";
        parent::Display();
    }
}

/**
 * 具体装饰器
 * Class pixie
 */
class qiuxie extends Clothes
{
    function Display()
    {
        echo "球鞋";
        parent::Display();
    }
}

$a = new Person('A');
$b = new Person('B');

$qiuxie = new qiuxie();
$pixie = new pixie();

$qiuxie->Decorate($a);
$pixie->Decorate($qiuxie);
$pixie->Display();
